package com.java110.mall.cart.bmo.storeOrderCartSend.impl;

import com.java110.mall.cart.bmo.storeOrderCartSend.IGetStoreOrderCartSendBMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.java110.intf.cart.IStoreOrderCartSendInnerServiceSMO;
import com.java110.dto.storeOrder.StoreOrderCartSendDto;
import org.springframework.http.HttpStatus;

import java.util.ArrayList;
import java.util.List;

@Service("getStoreOrderCartSendBMOImpl")
public class GetStoreOrderCartSendBMOImpl implements IGetStoreOrderCartSendBMO {

    @Autowired
    private IStoreOrderCartSendInnerServiceSMO storeOrderCartSendInnerServiceSMOImpl;

    /**
     *
     *
     * @param  storeOrderCartSendDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(StoreOrderCartSendDto storeOrderCartSendDto) {


        int count = storeOrderCartSendInnerServiceSMOImpl.queryStoreOrderCartSendsCount(storeOrderCartSendDto);

        List<StoreOrderCartSendDto> storeOrderCartSendDtos = null;
        if (count > 0) {
            storeOrderCartSendDtos = storeOrderCartSendInnerServiceSMOImpl.queryStoreOrderCartSends(storeOrderCartSendDto);
        } else {
            storeOrderCartSendDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) storeOrderCartSendDto.getRow()), count, storeOrderCartSendDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
